<template>
  <div id="dcontent" class="mui-content">
    <div class="mui-content-padded">
      <div class="mui-content-padded oauth-area">
        <div id="UN_WEB" class="mui-btn mui-btn-blue mui-btn-block pay">
          豪车之家订单支付平台
        </div>
      </div>
      <ul class="mui-table-view">
        <li class="mui-table-view-cell">
          订&nbsp;&nbsp;单&nbsp;&nbsp;号:
          <span id="o_serial">{{ orderId }}</span>
        </li>
        <li class="mui-table-view-cell">
          支付金额: <span id="o_money">{{ money | numFilter}}万</span>
        </li>
        <li class="mui-table-view-cell">
          会员类型: <span id="v_name ">{{ viplist.v_name }}</span>
        </li>
        <li class="mui-table-view-cell">
           折扣:<span id="o_money">{{ viplist.v_discount }}折</span>
        </li>
       
        <li class="mui-table-view-cell">
          下单时间:<span id="o_date">{{ data | dateFmt("YYYY-MM-DD") }}</span>
        </li>
        <li class="mui-table-view-cell">
          收货地址:
          <textarea name="" id="o_address" v-model="o_address" cols="20" rows="5"></textarea>
        </li>
        <li class="mui-table-view-cell">
          备注:<textarea  name=""  id="o_address"  v-model="o_comment"  cols="20" rows="5" ></textarea>
        </li>
      </ul>
      <button type="button"  class="mui-btn mui-btn-success mui-btn-block mui-btn-outlined"   @click="ordertable">提交订单</button>
    </div>
  </div>
</template>    
<script>
// import $ from 'jquery'
// import '../../lib/mui/js/province.js'
import {Toast} from 'mint-ui'
import moment from "moment";
export default {
  filters: {
    dateFmt: function (str, pattern) {
      return moment(str).format("YYYY-MM-DD HH:mm:ss");
    },
     numFilter (value) {
    // 截取当前数据到小数点后两位
    let realVal = parseFloat(value).toFixed(2)
    return realVal
     }
  },

  data() {
    return {
      orderId: new Date().getTime(),
      money: this.$route.params.money,
      uid: 0,
      data: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"),
      o_address: "",
      pids: this.$route.params.pids,
      o_comment:'' ,
      u_money:'',
      viplist:{},
    };
  },
  methods: { 
    ordertable() {
      let ordertable = {
        o_serial: this.orderId,
        o_money: this.money,
        o_date: this.data,
        o_address: this.o_address,
        o_u_id:this.uid,
        o_p_id:this.pids,
        o_comment:this.o_comment
      };
    
        this.$ajax({
        url:"before/addordertable",
        method:"post",
        data:ordertable
      }).then(resp=>{
        
      })
  
       this.$ajax({
              url:"users/getUser/"+this.uid,
              method:"get",
            }).then(resp=>{
                this.u_money=resp.data.message[0].u_money
                
                this.u_money=parseFloat(this.u_money) - parseFloat(this.$route.params.money)
                console.log(this.u_money);
              if(this.u_money<=0){
                Toast('余额不足')
                return
              }
                let person={
                "u_money":this.u_money,
                "u_id":this.uid
            }
                  this.$ajax({
                  url:'before/users',
                  method:'put',
                  data:person
            }).then(resp=>{
                localStorage.setItem('pids','')
                this.$router.push('/bill/Addbill/'+this.uid)
            })
       });  
    },  
    getvip(){
       this.$ajax({
              url:"before/uvinpkind/"+this.uid,
              method:"get",
            }).then(resp=>{
        this.viplist=resp.data.message[0]
        });
    }    
  },
  created() {
    let uid=JSON.parse(localStorage.getItem("uid")) 
    this.uid=uid
    let unbill=
      {
        pids:this.$route.params.pids,
        money:this.$route.params.money,
        orderId:this.orderId,
        data:this.data
      }
    localStorage.setItem('unbills',JSON.stringify(unbill))
    this.getvip()
  },
};
</script>

<style scoped>
</style>